package com.huike.stock_analysis.dao;


import java.text.DecimalFormat;
import java.util.ArrayList;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Repository;

@Repository
public class OverviewDao {


	@Autowired
	private JdbcTemplate jdbcTemplate;
	
	private DecimalFormat df = new DecimalFormat("0.0000");
	
	/**
	 * 
	 * @param code
	 * @return
	 * 查询雷达图需要数据
	 */
	public List<String> queryRadar(String code){
		List<String> radar = new ArrayList<>();
		String sql = "SELECT avg(`ads_yylrl`) FROM `ads_ylnl` WHERE `ads_id` = " + code;
		radar.add(df.format(jdbcTemplate.queryForObject(sql, Double.class).doubleValue()));
		sql = "SELECT `ads_hypjyylrl` FROM `ads_ylnl` WHERE `ads_id` = " + code + " ORDER BY `ads_date` LIMIT 1";
		radar.add(df.format(jdbcTemplate.queryForObject(sql, Double.class).doubleValue()));
		sql = "SELECT max(`ads_hypjyylrl`) FROM `ads_ylnl`";
		radar.add(df.format(jdbcTemplate.queryForObject(sql, Double.class).doubleValue()));
		sql = "SELECT min(`ads_hypjyylrl`)  FROM `ads_ylnl`";
		radar.add(df.format(jdbcTemplate.queryForObject(sql, Double.class).doubleValue()));
		
		sql = "SELECT avg(`ads_zyywsrzzl`) FROM `ads_chengzhangnengli` WHERE `ads_id` = " + code;
		radar.add(df.format(jdbcTemplate.queryForObject(sql, Double.class).doubleValue()));
		sql = "SELECT `ads_hypjzyywsrzzl` FROM `ads_chengzhangnengli` WHERE `ads_id` = " + code + " ORDER BY `ads_date` LIMIT 1";
		radar.add(df.format(jdbcTemplate.queryForObject(sql, Double.class).doubleValue()));
		sql = "SELECT max(`ads_hypjzyywsrzzl`) FROM `ads_chengzhangnengli`";
		radar.add(df.format(jdbcTemplate.queryForObject(sql, Double.class).doubleValue()));
		sql = "SELECT min(`ads_hypjzyywsrzzl`) FROM `ads_chengzhangnengli`";
		radar.add(df.format(jdbcTemplate.queryForObject(sql, Double.class).doubleValue()));
		
		sql = "SELECT avg(`ads_zzczzl`) FROM `ads_yynl` WHERE `ads_id` = " + code;
		radar.add(df.format(jdbcTemplate.queryForObject(sql, Double.class).doubleValue()));
		sql = "SELECT `ads_hypjzzczzl` FROM `ads_yynl` WHERE `ads_id` = " + code + " ORDER BY `ads_date` LIMIT 1";
		radar.add(df.format(jdbcTemplate.queryForObject(sql, Double.class).doubleValue()));
		sql = "SELECT max(`ads_hypjzzczzl`) FROM `ads_yynl`";
		radar.add(df.format(jdbcTemplate.queryForObject(sql, Double.class).doubleValue()));
		sql = "SELECT min(`ads_hypjzzczzl`) FROM `ads_yynl`";
		radar.add(df.format(jdbcTemplate.queryForObject(sql, Double.class).doubleValue()));
		
		sql = "SELECT avg(`ads_ldbl`) FROM `ads_changzhainengli` WHERE `ads_id` = " + code;
		radar.add(df.format(jdbcTemplate.queryForObject(sql, Double.class).doubleValue()));
		sql = "SELECT `ads_hypjldbl` FROM `ads_changzhainengli` WHERE `ads_id` = " + code + " ORDER BY `ads_date` LIMIT 1";
		radar.add(df.format(jdbcTemplate.queryForObject(sql, Double.class).doubleValue()));
		sql = "SELECT max(`ads_hypjldbl`) FROM `ads_changzhainengli`";
		radar.add(df.format(jdbcTemplate.queryForObject(sql, Double.class).doubleValue()));
		sql = "SELECT min(`ads_hypjldbl`) FROM `ads_changzhainengli`";
		radar.add(df.format(jdbcTemplate.queryForObject(sql, Double.class).doubleValue()));
		
		sql = "SELECT avg(`ads_zz`) FROM `ads_fxgb` WHERE `ads_id` = " + code;
		radar.add(df.format(jdbcTemplate.queryForObject(sql, Double.class).doubleValue()));
		
		sql = "SELECT avg(`ads_zlzjjlr`) FROM `ads_zjtj1` WHERE `ads_id` = " + code;
		radar.add(df.format(jdbcTemplate.queryForObject(sql, Double.class).doubleValue()));
		sql = "SELECT `ads_hypjzlzjjlr` FROM `ads_zjtj1` WHERE `ads_id` = " + code + " ORDER BY `ads_date` LIMIT 1";
		radar.add(df.format(jdbcTemplate.queryForObject(sql, Double.class).doubleValue()));
		sql = "SELECT max(`ads_hypjzlzjjlr`) FROM `ads_zjtj1`";
		radar.add(df.format(jdbcTemplate.queryForObject(sql, Double.class).doubleValue()));
		sql = "SELECT min(`ads_hypjzlzjjlr`) FROM `ads_zjtj1`";
		radar.add(df.format(jdbcTemplate.queryForObject(sql, Double.class).doubleValue()));
		
		return radar;
		
		
		
	}
}
